/*     */ package com.zimbra.cs.wiki;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.MapUtil;
/*     */ import com.zimbra.common.util.Pair;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.cs.mailbox.MailItem;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class PageCache
/*     */ {
/*     */   private static final int DEFAULT_CACHE_SIZE = 10240;
/*     */   private static final int TTL = 600000;
/*     */   private Map mCache;
/*     */   private static final String SEP = ":";
/*     */   
/*     */   public PageCache()
/*     */   {
/*  53 */     Provisioning prov = Provisioning.getInstance();
/*     */     int cacheSize;
/*     */     try {
/*  56 */       Server localServer = prov.getLocalServer();
/*  57 */       cacheSize = localServer.getIntAttr("zimbraNotebookPageCacheSize", 10240);
/*     */     } catch (ServiceException se) {
/*  59 */       cacheSize = 10240;
/*     */     }
/*  61 */     this.mCache = MapUtil.newLruMap(cacheSize);
/*     */   }
/*     */   
/*  64 */   public PageCache(int cacheSize) { this.mCache = MapUtil.newLruMap(cacheSize); }
/*     */   
/*     */   public synchronized void addPage(String key, String page)
/*     */   {
/*  68 */     Pair<Long, String> v = new Pair(Long.valueOf(getExpirationTime()), page);
/*  69 */     this.mCache.put(key, v);
/*     */   }
/*     */   
/*     */   private long getExpirationTime() {
/*  73 */     return System.currentTimeMillis() + 600000L;
/*     */   }
/*     */   
/*     */   public synchronized String getPage(String key) {
/*  77 */     Pair v = (Pair)this.mCache.get(key);
/*  78 */     if ((v != null) && (((Long)v.getFirst()).longValue() < System.currentTimeMillis())) {
/*  79 */       this.mCache.remove(key);
/*  80 */       v = null;
/*     */     }
/*  82 */     if (v == null)
/*  83 */       return null;
/*  84 */     return (String)v.getSecond();
/*     */   }
/*     */   
/*     */   public synchronized void removePage(String key) {
/*  88 */     Pair v = (Pair)this.mCache.get(key);
/*  89 */     if (v != null)
/*  90 */       this.mCache.remove(key);
/*     */   }
/*     */   
/*     */   public String generateKey(Account user, MailItem item) { String auth;
/*     */     String auth;
/*  95 */     if (user == null) {
/*  96 */       auth = "guest";
/*     */     } else
/*  98 */       auth = user.getId();
/*  99 */     StringBuilder buf = new StringBuilder();
/* 100 */     buf.append(auth).append(":").append(item.getMailboxId()).append(":").append(item.getId());
/* 101 */     return buf.toString();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/wiki/PageCache.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */